<template>
	<view>
		<h1 style="text-align: center;">骑行记录</h1>
		<view class="Box">
			<view class="list" v-for="(item,index) in datas" :key="index">
				{{dateFormat(item.startTime)}}---{{dateFormat(item.endTime)}}
			</view>
		</view>
	</view>
</template>

<script>
	import store from '@/store/index.js'; //需要引入store
	export default {
		data() {
			return {
				startTime: '',
				endTime: '',
				datas: []
			}
		},

		onShow() {
			uni.request({
				url: 'http://172.20.10.5:8080/user/history',
				header: {
					'content-type': 'application/json',
				},
				data: {
					userAccount: store.state.user.account
				},
				method: 'POST',
				success: (res) => {
					console.log(res)
					this.datas = res.data
				}
			})
		},

		methods: {
			dateFormat(value) {
				var date = new Date(value); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var year = date.getFullYear();
				var month = ("0" + (date.getMonth() + 1)).slice(-2);
				var sdate = ("0" + date.getDate()).slice(-2);
				var hour = ("0" + date.getHours()).slice(-2);
				//console.log(date.getMinutes())
				var minute = ("0" + date.getMinutes()).slice(-2);
				var second = ("0" + date.getSeconds()).slice(-2);
				// 拼接
				var result = year + "/" + month + "/" + sdate + " " + hour + ":" + minute + ":" + second;
				// 返回

				return result;
			},
		}
	}
</script>

<style>
	.list {
		height: 30px;
		line-height: 30px;
		margin-top: 20px;
		font-size: 17px;
		font-weight: 700;
		text-align: center;
	}
	
	.Box {
		background-color: #f9c327;
	}
</style>
